package book;

import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description: 此类来描绘书架
 * Author:  LiuTao
 * Version: 1.0
 * Date:    2024-01-03  08:46
 */
public class BookList {
    private Book[] books;
    //记录书架上书的数目
    private int usedSize;
    private static int DEFAULT_CAPACITY = 3;

    //初始化书架的大小
    public BookList() { 
        this.books = new Book[DEFAULT_CAPACITY];
        this.books[0] = new Book("三国演义","罗贯中",10,"小说");
        this.books[1] = new Book("西游记","吴承恩",20,"小说");
        this.books[2] = new Book("红楼梦","曹雪芹",30,"小说");

        usedSize = 3;
    }

    // 当数组满时，进行扩容（这里简单地扩容为原来的两倍）
    public void addBook(Book book) {
        if (usedSize == books.length) {
            books = Arrays.copyOf(books, books.length * 2);
        }
    }

    public int getLength() {
        return books.length;
    }
    public int getUsedSize() {
        return usedSize;
    }

    public void setUsedSize(int usedSize) {
        this.usedSize = usedSize;
    }

    //获取pos位置的书
    public Book getBook(int pos) {
        return books[pos];
    }

    //进书放在pos位置
    public void setBooks(int pos, Book book) {
        this.books[pos] = book;
    }
}
